﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.AccessControl;
using System.Text;
using System.Threading.Tasks;
using _01.策略模式.Enums;
using _01.策略模式.Factories;
using _01.策略模式.Strategies;

namespace _01.策略模式.Entities
{
    /// <summary>
    /// 订单领域实体
    /// </summary>
    public class Order : BaseEntity
    {
        private decimal _settlementAmount;

        public Order() { }

        public Order(Customer customer)
        {
            this.Customer = customer;
            this._settlementAmount = Amount;
        }

        /// <summary>
        /// 订单编号
        /// </summary>
        public string Number { get; set; }

        /// <summary>
        /// 客户Id
        /// </summary>
        public Guid CustomerId { get; set; }

        /// <summary>
        /// 客户
        /// </summary>
        public virtual Customer Customer { get; set; }

        /// <summary>
        /// 订单总额，只读属性，计算获得
        /// </summary>
        public decimal Amount { get { return 10000; } }

        /// <summary>
        /// 订单结算金额，订单总额适用折扣后的金额
        /// </summary>
        public decimal SettlementAmount
        {
            get { return _settlementAmount; }
        }

        /// <summary>
        /// 适用客户折扣策略
        /// </summary>
        public void ApplyCustomerDiscount()
        {
            //获取折扣策略，客户策略
            IDiscountStrategy discountStrategy = DiscountFactory.GetDiscountStrategy(this.Customer.CustomerType);

            //适用折扣策略
            this._settlementAmount = discountStrategy.ApplyOrderDiscount(this.SettlementAmount);
        }

        /// <summary>
        /// 适用大额订单折扣策略
        /// </summary>
        public void ApplyLargeOrderDiscount()
        {
            //获取折扣策略，订单额度策略
            IDiscountStrategy orderDiscountStrategy = DiscountFactory.GetDiscountStrategy(this.SettlementAmount);

            //适用折扣策略
            this._settlementAmount = orderDiscountStrategy.ApplyOrderDiscount(this.SettlementAmount);
        }
    }
}
